package com.aaa.phone.controller.registercontroller;

import com.aaa.phone.service.registerservice.IRegisterService;
import com.aaa.util.MessageUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: batterysharing
 * @description: 短信验证码注册
 * @author: 王璐
 * @create: 2018-12-14 14:42
 **/

@CrossOrigin
@RestController
@RequestMapping("/register")
public class Register {

    /**
     * 自动注入
     */
    @Autowired
    private IRegisterService service;

    /**
     * 日志
     */
    private Logger log = LogManager.getLogger(getClass());

    /**
     * @Description: 获取短信验证码
     * @Author: 王璐
     * @Date: 2018/12/14
    */ 
    @RequestMapping("/getCode")
    public int getCode(String tel){
        int code = Integer.parseInt(MessageUtil.getMessageCode(tel));
        log.debug(tel+"---------------");
        return code;
    }

    /**
     * @Description: 用户注册
     * @Author: 王璐
     * @Date: 2018/12/14
    */ 
    @RequestMapping("/addUser")
    public int addUser(String tel, String psw){
        //注册成功返回100   失败200
        return service.userRegister(tel, psw);
    }
}
